﻿using System;
using System.Windows.Controls;
using System.Windows.Data;

namespace InvokeCommandActionWithEventArgs
{
    /// <summary>
    /// SelectionChangedEventをCommandParameterに変換するIValueConverterの実装
    /// </summary>
    public class SelectionChangedEventArgsToCommandParameterConverter<T> : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var args = (SelectionChangedEventArgs)value;
            return new SelectionChangedCommandParameter<T>(args.RemovedItems, args.AddedItems);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    /// <summary>
    /// Xamlで型引数を使用するためのラップクラス（Xaml2009・・・。）
    /// </summary>
    public class SelectionChangedEventArgsToCommandParameterConverter : SelectionChangedEventArgsToCommandParameterConverter<Person>
    { }
}
